<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="部门名称" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入部门名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备名称" prop="eqpName">
        <el-input
          v-model="queryParams.eqpName"
          placeholder="请输入设备名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备负责人" prop="eqpMaster" label-width="88px">
        <el-input
          v-model="queryParams.eqpMaster"
          placeholder="请输入设备负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.equip_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['equipment:equip:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['equipment:equip:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['equipment:equip:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['equipment:equip:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="equipList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" type="index" width="50"/>
      <el-table-column label="设备名称" align="center" prop="eqpName" width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-button type="text" title="查看设备台账" @click="handleViewLedger(scope.row)">{{ scope.row.eqpName }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="部门名称" align="center" prop="deptName" width="130" show-overflow-tooltip />
      <el-table-column label="设备类型" align="center" prop="eqpTypeName" width="130" show-overflow-tooltip />
      <el-table-column label="设备型号" align="center" prop="eqpModel" width="130" show-overflow-tooltip />
      <el-table-column label="设备品牌" align="center" prop="eqpBrand" width="130" show-overflow-tooltip />
      <el-table-column label="设备价格" align="center" prop="eqpPrice"/>
      <el-table-column label="设备负责人" align="center" prop="eqpMaster"/>
      <el-table-column label="出厂编号" align="center" prop="factoryCode"/>
      <el-table-column label="采购日期" align="center" prop="buyDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.buyDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.equip_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['equipment:equip:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['equipment:equip:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改设备对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="部门名称" prop="deptId">
              <treeselect v-model="form.deptId" :options="deptOptions" :normalizer="deptNormalizer"
                          @select="handleDeptName" placeholder="选择部门"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备类别" prop="eqpTypeId">
              <treeselect v-model="form.eqpTypeId" :options="equipTypeOptions" :normalizer="equipTypeNormalizer"
                          @select="handleTypeName" placeholder="请选择设备类型"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="设备名称" prop="eqpName">
              <el-input v-model="form.eqpName" placeholder="请输入设备名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备型号" prop="eqpModel">
              <el-input v-model="form.eqpModel" placeholder="请输入设备型号"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="设备品牌" prop="eqpBrand">
              <el-input v-model="form.eqpBrand" placeholder="请输入设备品牌"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供应商" prop="supplier">
              <el-input v-model="form.supplier" placeholder="请输入供应商"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="采购日期" prop="buyDate">
              <el-date-picker clearable
                              v-model="form.buyDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              style="width: 100%"
                              placeholder="请选择采购日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备价格" prop="eqpPrice">
              <el-input v-model="form.eqpPrice" placeholder="请输入设备价格"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="设备负责人" prop="eqpMaster" label-width="98px">
              <el-input v-model="form.eqpMaster" placeholder="请输入设备负责人"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备位置" prop="eqpPlace">
              <el-input v-model="form.eqpPlace" placeholder="请输入设备位置"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="出厂编号" prop="factoryCode">
              <el-input v-model="form.factoryCode" placeholder="请输入出厂编号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备年龄" prop="eqpAge">
              <el-input v-model="form.eqpAge" placeholder="请输入设备年龄"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-select v-model="form.status" placeholder="请选择状态" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.equip_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" maxlength="255" show-word-limit/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--  设备台账内容  -->
    <el-drawer
      size="75%"
      :title="eqpNameTitle"
      :visible.sync="drawer"
    >
      <el-tabs active-name="baseInfo" @tab-click="handleTabClick" style="padding: 0 16px 16px">
        <el-tab-pane label="基本信息" name="baseInfo">
          <el-form ref="baseInfoForm" :model="baseInfoForm" label-width="80px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="部门名称" prop="deptId">
                  {{ baseInfoForm.deptName }}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="设备类别" prop="eqpTypeId">
                  {{ baseInfoForm.eqpTypeName }}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="设备名称" prop="eqpName">
                  {{ baseInfoForm.eqpName }}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="设备型号" prop="eqpModel">
                  {{ baseInfoForm.eqpModel }}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="设备品牌" prop="eqpBrand">
                  {{ baseInfoForm.eqpBrand }}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="供应商" prop="supplier">
                  {{ baseInfoForm.supplier }}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="采购日期" prop="buyDate">
                  {{ baseInfoForm.buyDate }}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="设备价格" prop="eqpPrice">
                  {{ baseInfoForm.eqpPrice }}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="设备负责人" prop="eqpMaster" label-width="98px">
                  {{ baseInfoForm.eqpMaster }}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="设备位置" prop="eqpPlace">
                  {{ baseInfoForm.eqpPlace }}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="出厂编号" prop="factoryCode">
                  {{ baseInfoForm.factoryCode }}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="设备年龄" prop="eqpAge">
                  {{ baseInfoForm.eqpAge }}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="状态" prop="status">
                  <dict-tag :options="dict.type.equip_status" :value="baseInfoForm.status"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="备注" prop="remark">
              {{ baseInfoForm.remark }}
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="运行记录" name="record">
          <el-form :model="recordQueryParams" ref="recordQueryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="停机类型" prop="stopType">
              <el-select v-model="recordQueryParams.stopType" placeholder="请选择停机类型" clearable>
                <el-option
                  v-for="dict in dict.type.stop_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="停机人" prop="operatorBy">
              <el-input
                v-model="recordQueryParams.operatorBy"
                placeholder="请输入停机人"
                clearable
                @keyup.enter.native="recordHandleQuery"
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="recordHandleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="recordResetQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <el-table :data="recordList">
            <el-table-column label="序号" type="index" width="50"/>
            <el-table-column label="设备名称" align="center" prop="eqpName"/>
            <el-table-column label="记录时间" align="center" prop="recordDate" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.recordDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="开机时间" align="center" prop="startTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="关机时间" align="center" prop="stopTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.stopTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="计划停机时间" align="center" prop="planStopTime"/>
            <el-table-column label="异常停机时间" align="center" prop="exceptionStopTime"/>
            <el-table-column label="停机类型" align="center" prop="stopType">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.stop_type" :value="scope.row.stopType"/>
              </template>
            </el-table-column>
            <el-table-column label="停机人" align="center" prop="operatorBy"/>
            <el-table-column label="状态" align="center" prop="status">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="recordTotal>0"
            :total="recordTotal"
            :page.sync="recordQueryParams.pageNum"
            :limit.sync="recordQueryParams.pageSize"
            @pagination="getRecordList"
          />
        </el-tab-pane>
        <el-tab-pane label="备品备件" name="part">
          <el-form :model="partQueryParams" ref="partQueryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="备件编码" prop="sparePartCode">
              <el-input
                v-model="partQueryParams.sparePartCode"
                placeholder="请输入备件编码"
                clearable
                @keyup.enter.native="handlePartQuery"
              />
            </el-form-item>
            <el-form-item label="备件名称" prop="sparePartName">
              <el-input
                v-model="partQueryParams.sparePartName"
                placeholder="请输入备件名称"
                clearable
                @keyup.enter.native="handlePartQuery"
              />
            </el-form-item>
            <el-form-item label="备件类型" prop="sparePartType">
              <el-select v-model="partQueryParams.sparePartType" placeholder="请选择备件类型" clearable>
                <el-option
                  v-for="dict in dict.type.spare_part_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handlePartQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetPartQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handlePartAdd"
                v-hasPermi="['equipment:part:add']"
              >关联备品备件
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="danger"
                plain
                icon="el-icon-delete"
                size="mini"
                :disabled="partMultiple"
                @click="handlePartDelete"
                v-hasPermi="['equipment:part:remove']"
              >移除备品备件
              </el-button>
            </el-col>
          </el-row>
          <el-table :data="partList" @selection-change="handleRemovePartSelectionChange">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="序号" type="index" width="50"/>
            <el-table-column label="备件编码" align="center" prop="sparePartCode"/>
            <el-table-column label="备件名称" align="center" prop="sparePartName"/>
            <el-table-column label="规格型号" align="center" prop="sparePartModel"/>
            <el-table-column label="备件类型" align="center" prop="sparePartType">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.spare_part_type" :value="scope.row.sparePartType"/>
              </template>
            </el-table-column>
            <el-table-column label="生产厂商" align="center" prop="production"/>
            <el-table-column label="供应商" align="center" prop="supplier"/>
            <el-table-column label="单位" align="center" prop="unit"/>
            <el-table-column label="单价" align="center" prop="price"/>
            <el-table-column label="状态" align="center" prop="status">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="partTotal>0"
            :total="partTotal"
            :page.sync="partQueryParams.pageNum"
            :limit.sync="partQueryParams.pageSize"
            @pagination="getPartList"
          />

        </el-tab-pane>
        <el-tab-pane label="状态评估记录" name="statusRecord">
          <el-form :model="statusQueryParams" ref="statusQueryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="任务编号" prop="taskCode">
              <el-input
                v-model="statusQueryParams.taskCode"
                placeholder="请输入任务编号"
                clearable
                @keyup.enter.native="handleStatusQuery"
              />
            </el-form-item>
            <el-form-item label="任务名称" prop="taskName">
              <el-input
                v-model="statusQueryParams.taskName"
                placeholder="请输入任务名称"
                clearable
                @keyup.enter.native="handleStatusQuery"
              />
            </el-form-item>
            <el-form-item label="任务执行时间" label-width="120px">
              <el-date-picker
                v-model="statusDaterangeExecTime"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleStatusQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetStatusQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <el-table :data="statusRecordList">
            <el-table-column label="序号" type="index" width="50"/>
            <el-table-column label="任务编号" align="center" prop="taskCode" width="130" show-overflow-tooltip/>
            <el-table-column label="任务名称" align="center" prop="taskName" width="130" show-overflow-tooltip/>
            <el-table-column label="设备名称" align="center" prop="eqpName" width="130" show-overflow-tooltip/>
            <el-table-column label="算法编码" align="center" prop="algorithmCode" width="130" show-overflow-tooltip/>
            <el-table-column label="算法名称" align="center" prop="algorithmName" width="130" show-overflow-tooltip/>
            <el-table-column label="算法类型" align="center" prop="algorithmType" width="130" show-overflow-tooltip>
              <template slot-scope="scope">
                <dict-tag :options="dict.type.algorithm_type" :value="scope.row.algorithmType"/>
              </template>
            </el-table-column>
            <el-table-column label="任务执行时间" align="center" prop="execTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.execTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="任务执行人" align="center" prop="execBy"/>
            <el-table-column label="算法运行时长" align="center" prop="runTime">
              <template slot-scope="scope">
                {{ scope.row.runTime }} ms
              </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="statusTotal>0"
            :total="statusTotal"
            :page.sync="statusQueryParams.pageNum"
            :limit.sync="statusQueryParams.pageSize"
            @pagination="getStatusRecordList"
          />

        </el-tab-pane>
        <el-tab-pane label="寿命预测记录" name="lifeRecord">
          <el-form :model="lifeQueryParams" ref="lifeQueryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="任务编号" prop="taskCode">
              <el-input
                v-model="lifeQueryParams.taskCode"
                placeholder="请输入任务编号"
                clearable
                @keyup.enter.native="handleLifeQuery"
              />
            </el-form-item>
            <el-form-item label="任务名称" prop="taskName">
              <el-input
                v-model="lifeQueryParams.taskName"
                placeholder="请输入任务名称"
                clearable
                @keyup.enter.native="handleLifeQuery"
              />
            </el-form-item>
            <el-form-item label="任务执行时间" label-width="120px">
              <el-date-picker
                v-model="lifeDaterangeExecTime"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleLifeQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetLifeQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <el-table :data="lifeRecordList">
            <el-table-column label="序号" type="index" width="50"/>
            <el-table-column label="任务编号" align="center" prop="taskCode" width="130" show-overflow-tooltip/>
            <el-table-column label="任务名称" align="center" prop="taskName" width="130" show-overflow-tooltip/>
            <el-table-column label="设备名称" align="center" prop="eqpName" width="130" show-overflow-tooltip/>
            <el-table-column label="算法编码" align="center" prop="algorithmCode" width="130" show-overflow-tooltip/>
            <el-table-column label="算法名称" align="center" prop="algorithmName" width="130" show-overflow-tooltip/>
            <el-table-column label="算法类型" align="center" prop="algorithmType" width="130" show-overflow-tooltip>
              <template slot-scope="scope">
                <dict-tag :options="dict.type.algorithm_type" :value="scope.row.algorithmType"/>
              </template>
            </el-table-column>
            <el-table-column label="任务执行时间" align="center" prop="execTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.execTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="任务执行人" align="center" prop="execBy"/>
            <el-table-column label="算法运行时长" align="center" prop="runTime">
              <template slot-scope="scope">
                {{ scope.row.runTime }} ms
              </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="lifeTotal>0"
            :total="lifeTotal"
            :page.sync="lifeQueryParams.pageNum"
            :limit.sync="lifeQueryParams.pageSize"
            @pagination="getLifeRecordList"
          />
        </el-tab-pane>
        <el-tab-pane label="设备故障记录" name="faultRecord">
          <el-form :model="faultQueryParams" ref="faultQueryForm" size="small" :inline="true" v-show="showSearch"
                   label-width="68px"
          >
            <el-form-item label="故障名称" prop="faultName">
              <el-input
                v-model="faultQueryParams.faultName"
                placeholder="请输入故障名称"
                clearable
                @keyup.enter.native="handleFaultQuery"
              />
            </el-form-item>
            <el-form-item label="故障时间">
              <el-date-picker
                v-model="faultDaterangeExecTime"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleFaultQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetFaultQuery">重置</el-button>
            </el-form-item>
          </el-form>

          <el-table :data="faultRecordList">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="序号" type="index" width="50"/>
            <el-table-column label="设备编号" align="center" prop="eqpId"/>
            <el-table-column label="设备名称" align="center" prop="eqpName"/>
            <el-table-column label="故障名称" align="center" prop="faultName"/>
            <el-table-column label="发现人员" align="center" prop="faultBy"/>
            <el-table-column label="故障时间" align="center" prop="faultTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.faultTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="处理人员" align="center" prop="handleBy"/>
            <el-table-column label="处理时间" align="center" prop="handleTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.handleTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="处理结果" align="center" prop="handleResult"/>
            <el-table-column label="处理耗时" align="center" prop="handleDuration">
              <template slot-scope="scope">
                <span>{{ parseTimeMillis(scope.row.handleDuration) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="faultTotal>0"
            :total="faultTotal"
            :page.sync="faultQueryParams.pageNum"
            :limit.sync="faultQueryParams.pageSize"
            @pagination="getFaultRecordList"
          />
        </el-tab-pane>
        <el-tab-pane label="故障诊断记录" name="diagnosisRecord">
          <el-form :model="diagnosisQueryParams" ref="diagnosisQueryForm" size="small" :inline="true"
                   label-width="68px"
          >
            <el-form-item label="任务编号" prop="taskCode">
              <el-input
                v-model="diagnosisQueryParams.taskCode"
                placeholder="请输入任务编号"
                clearable
                @keyup.enter.native="handleDiagnosisQuery"
              />
            </el-form-item>
            <el-form-item label="任务名称" prop="taskName">
              <el-input
                v-model="diagnosisQueryParams.taskName"
                placeholder="请输入任务名称"
                clearable
                @keyup.enter.native="handleDiagnosisQuery"
              />
            </el-form-item>
            <el-form-item label="任务执行时间" label-width="120px">
              <el-date-picker
                v-model="diagnosisDaterangeExecTime"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleDiagnosisQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetDiagnosisQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <el-table :data="diagnosisRecordList">
            <el-table-column label="序号" type="index" width="50"/>
            <el-table-column label="任务编号" align="center" prop="taskCode" width="130" show-overflow-tooltip/>
            <el-table-column label="任务名称" align="center" prop="taskName" width="130" show-overflow-tooltip/>
            <el-table-column label="设备名称" align="center" prop="eqpName" width="130" show-overflow-tooltip/>
            <el-table-column label="算法编码" align="center" prop="algorithmCode" width="130" show-overflow-tooltip/>
            <el-table-column label="算法名称" align="center" prop="algorithmName" width="130" show-overflow-tooltip/>
            <el-table-column label="算法类型" align="center" prop="algorithmType" width="130" show-overflow-tooltip>
              <template slot-scope="scope">
                <dict-tag :options="dict.type.algorithm_type" :value="scope.row.algorithmType"/>
              </template>
            </el-table-column>
            <el-table-column label="任务执行时间" align="center" prop="execTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.execTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="任务执行人" align="center" prop="execBy"/>
            <el-table-column label="算法运行时长" align="center" prop="runTime">
              <template slot-scope="scope">
                {{ scope.row.runTime }} ms
              </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="diagnosisTotal>0"
            :total="diagnosisTotal"
            :page.sync="diagnosisQueryParams.pageNum"
            :limit.sync="diagnosisQueryParams.pageSize"
            @pagination="getDiagnosisRecordList"
          />
        </el-tab-pane>
        <el-tab-pane label="维修决策记录" name="decisionRecord">
          <el-form :model="decisionQueryParams" ref="decisionQueryForm" size="small" :inline="true"
                   label-width="68px"
          >
            <el-form-item label="任务编号" prop="taskCode">
              <el-input
                v-model="decisionQueryParams.taskCode"
                placeholder="请输入任务编号"
                clearable
                @keyup.enter.native="handleDecisionQuery"
              />
            </el-form-item>
            <el-form-item label="任务名称" prop="taskName">
              <el-input
                v-model="decisionQueryParams.taskName"
                placeholder="请输入任务名称"
                clearable
                @keyup.enter.native="handleDecisionQuery"
              />
            </el-form-item>
            <el-form-item label="任务执行时间" label-width="120px">
              <el-date-picker
                v-model="decisionDaterangeExecTime"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleDecisionQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetDecisionQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <el-table :data="decisionRecordList">
            <el-table-column label="序号" type="index" width="50"/>
            <el-table-column label="任务编号" align="center" prop="taskCode" width="130" show-overflow-tooltip/>
            <el-table-column label="任务名称" align="center" prop="taskName" width="130" show-overflow-tooltip/>
            <el-table-column label="设备名称" align="center" prop="eqpName" width="130" show-overflow-tooltip/>
            <el-table-column label="算法编码" align="center" prop="algorithmCode" width="130" show-overflow-tooltip/>
            <el-table-column label="算法名称" align="center" prop="algorithmName" width="130" show-overflow-tooltip/>
            <el-table-column label="算法类型" align="center" prop="algorithmType" width="130" show-overflow-tooltip>
              <template slot-scope="scope">
                <dict-tag :options="dict.type.algorithm_type" :value="scope.row.algorithmType"/>
              </template>
            </el-table-column>
            <el-table-column label="任务执行时间" align="center" prop="execTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.execTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="任务执行人" align="center" prop="execBy"/>
            <el-table-column label="算法运行时长" align="center" prop="runTime">
              <template slot-scope="scope">
                {{ scope.row.runTime }} ms
              </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="decisionTotal>0"
            :total="decisionTotal"
            :page.sync="decisionQueryParams.pageNum"
            :limit.sync="decisionQueryParams.pageSize"
            @pagination="getDecisionRecordList"
          />
        </el-tab-pane>
      </el-tabs>
    </el-drawer>
    <el-dialog
      title="选择备品备件"
      :visible.sync="dialogVisible"
      width="40%"
      :before-close="handleEquipPartClose"
    >
      <div class="form-overflow-hide">
        <el-form :model="addPartQueryParams" ref="addPartQueryForm" size="small" :inline="true" label-width="68px">
          <el-form-item label="备件编码" prop="sparePartCode">
            <el-input
              v-model="addPartQueryParams.sparePartCode"
              placeholder="请输入备件编码"
              clearable
              @keyup.enter.native="handleAddPartQuery"
            />
          </el-form-item>
          <el-form-item label="备件名称" prop="sparePartName">
            <el-input
              v-model="addPartQueryParams.sparePartName"
              placeholder="请输入备件名称"
              clearable
              @keyup.enter.native="handleAddPartQuery"
            />
          </el-form-item>
          <el-form-item label="备件类型" prop="sparePartType">
            <el-select v-model="addPartQueryParams.sparePartType" placeholder="请选择备件类型" clearable>
              <el-option
                v-for="dict in dict.type.spare_part_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleAddPartQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetAddPartQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table :data="addPartList" ref="multipleTable" row-key="sparePartId" @selection-change="handlePartSelectionChange">
          <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
          <el-table-column label="序号" type="index" width="50"/>
          <el-table-column label="备件编码" align="center" prop="sparePartCode"/>
          <el-table-column label="备件名称" align="center" prop="sparePartName"/>
          <el-table-column label="规格型号" align="center" prop="sparePartModel"/>
          <el-table-column label="备件类型" align="center" prop="sparePartType">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.spare_part_type" :value="scope.row.sparePartType"/>
            </template>
          </el-table-column>
          <!--          <el-table-column label="生产厂商" align="center" prop="production" />-->
          <!--          <el-table-column label="供应商" align="center" prop="supplier" />-->
          <!--          <el-table-column label="单位" align="center" prop="unit" />-->
          <!--          <el-table-column label="单价" align="center" prop="price" />-->
          <el-table-column label="状态" align="center" prop="status">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="addPartTotal>0"
          :total="addPartTotal"
          :page.sync="addPartQueryParams.pageNum"
          :limit.sync="addPartQueryParams.pageSize"
          @pagination="getAddPartList"
        />
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="handleAddEquipPart">确 定</el-button>
  </span>
    </el-dialog>

  </div>
</template>

<script>
import { listEquip, getEquip, delEquip, addEquip, updateEquip } from '@/api/equipment/equip'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { listDept } from '@/api/system/dept'
import { listEquipType } from '@/api/equipment/equipType'
import { listRecord } from '@/api/equipment/record'
import { addEquipPart, delEquipPart, getBindSparePart, listPart } from '@/api/equipment/part'
import { listRecord as listAlgorithmRecord } from '@/api/algorithm/record'
import { listFaultRecord } from '@/api/equipment/faultRecord'

export default {
  name: 'Equip',
  dicts: ['equip_status', 'stop_type', 'sys_normal_disable', 'spare_part_type', 'algorithm_type'],
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备表格数据
      equipList: [],
      // 部门树选项
      deptOptions: [],
      // 设备类型树选项
      equipTypeOptions: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 是否弹出设备台账
      drawer: false,
      eqpNameTitle: '',
      baseInfoForm: {},
      // 运行记录------
      recordQueryParams: {
        pageNum: 1,
        pageSize: 10,
        eqpId: null,
        eqpName: null,
        stopType: null,
        operatorBy: null
      },
      // 总条数
      recordTotal: 0,
      // 设备运行记录表格数据
      recordList: [],
      // 运行记录------
      // 备品备件------
      dialogVisible: false,
      // 总条数
      addPartTotal: 0,
      // 设备备品备件表格数据
      addPartList: [],
      // 查询参数
      addPartQueryParams: {
        pageNum: 1,
        pageSize: 10,
        sparePartCode: null,
        sparePartName: null,
        sparePartType: null
      },
      partIds: [],
      removePartIds: [],
      partMultiple: true,
      // 总条数
      partTotal: 0,
      // 设备备品备件表格数据
      partList: [],
      // 查询参数
      partQueryParams: {
        pageNum: 1,
        pageSize: 10,
        eqpId: null,
        sparePartCode: null,
        sparePartName: null,
        sparePartType: null
      },
      // 备品备件------
      // 状态评估------
      // 总条数
      statusTotal: 0,
      // 算法状态评估记录表格数据
      statusRecordList: [],
      // 备注时间范围
      statusDaterangeExecTime: [],
      statusQueryParams: {
        pageNum: 1,
        pageSize: 10,
        taskCode: null,
        taskName: null,
        eqpId: null,
        algorithmType: 'combined_weighting'
      },
      // 状态评估------
      // 寿命预测------
      lifeTotal: 0,
      lifeRecordList: [],
      lifeDaterangeExecTime: [],
      lifeQueryParams: {
        pageNum: 1,
        pageSize: 10,
        taskCode: null,
        taskName: null,
        eqpId: null,
        algorithmType: 'markov'
      },
      // 寿命预测------
      // 设备故障------
      faultTotal: 0,
      faultRecordList: [],
      faultDaterangeExecTime: [],
      faultQueryParams: {
        pageNum: 1,
        pageSize: 10,
        eqpId: null,
        eqpName: null,
        faultName: null,
        faultBy: null,
        faultTime: null,
        faultReason: null,
        handleBy: null,
        handleTime: null,
        handleResult: null,
        handleDuration: null,
        status: null
      },
      // 设备故障------
      // 故障诊断------
      diagnosisTotal: 0,
      diagnosisRecordList: [],
      diagnosisDaterangeExecTime: [],
      diagnosisQueryParams: {
        pageNum: 1,
        pageSize: 10,
        taskCode: null,
        taskName: null,
        eqpId: null,
        algorithmType: 'neural_network_hidden_markov'
      },
      // 故障诊断------
      // 维修决策------
      decisionTotal: 0,
      decisionRecordList: [],
      decisionDaterangeExecTime: [],
      decisionQueryParams: {
        pageNum: 1,
        pageSize: 10,
        taskCode: null,
        taskName: null,
        eqpId: null,
        algorithmType: 'monte_carlo_simulation'
      },
      // 维修决策------
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: null,
        deptName: null,
        eqpTypeId: null,
        eqpTypeName: null,
        eqpName: null,
        eqpModel: null,
        eqpBrand: null,
        supplier: null,
        buyDate: null,
        eqpPrice: null,
        eqpPlace: null,
        eqpMaster: null,
        factoryCode: null,
        eqpAge: null,
        orderNum: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        deptId: [
          { required: true, message: '部门ID不能为空', trigger: 'blur' }
        ],
        eqpTypeId: [
          { required: true, message: '设备类别ID不能为空', trigger: 'blur' }
        ],
        eqpName: [
          { required: true, message: '设备名称不能为空', trigger: 'blur' }
        ],
        buyDate: [
          { required: true, message: '采购日期不能为空', trigger: 'blur' }
        ],
        eqpPrice: [
          { required: true, message: '设备价格不能为空', trigger: 'blur' }
        ],
        eqpMaster: [
          { required: true, message: '设备负责人不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询设备列表 */
    getList() {
      this.loading = true
      listEquip(this.queryParams).then(response => {
        this.equipList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 转换部门数据结构 */
    deptNormalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.deptId,
        label: node.deptName,
        children: node.children
      }
    },
    /** 转换类型数据结构 */
    equipTypeNormalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.eqpTypeId,
        label: node.typeName,
        children: node.children
      }
    },
    handleDeptName(node) {
      if (node) {
        this.form.deptName = node.deptName
      }
    },
    handleTypeName(node) {
      if (node) {
        this.form.eqpTypeName = node.typeName
      }
    },
    getTreeSelect() {
      listDept().then(response => {
        this.deptOptions = this.handleTree(response.data, 'deptId')
      })
      listEquipType().then(response => {
        this.equipTypeOptions = this.handleTree(response.data, 'eqpTypeId')
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        eqpId: null,
        deptId: null,
        deptName: null,
        eqpTypeId: null,
        eqpTypeName: null,
        eqpName: null,
        eqpModel: null,
        eqpBrand: null,
        supplier: null,
        buyDate: null,
        eqpPrice: null,
        eqpPlace: null,
        eqpMaster: null,
        factoryCode: null,
        eqpAge: null,
        orderNum: null,
        delFlag: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.eqpId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleViewLedger(row) {
      this.recordList = []
      this.partList = []
      this.statusRecordList = []
      this.lifeRecordList = []
      this.faultRecordList = []
      this.diagnosisRecordList = []
      this.decisionRecordList = []
      this.eqpNameTitle = row.eqpName
      this.baseInfoForm = row
      this.recordQueryParams.eqpId = row.eqpId
      this.partQueryParams.eqpId = row.eqpId
      this.statusQueryParams.eqpId = row.eqpId
      this.lifeQueryParams.eqpId = row.eqpId
      this.faultQueryParams.eqpId = row.eqpId
      this.decisionQueryParams.eqpId = row.eqpId
      this.diagnosisQueryParams.eqpId = row.eqpId
      this.drawer = true
    },
    handleTabClick(val) {
      if (val.name === 'record') {
        this.getRecordList()
      }
      if (val.name === 'part') {
        this.getPartList()
      }
      if (val.name === 'statusRecord') {
        this.getStatusRecordList()
      }
      if (val.name === 'lifeRecord') {
        this.getLifeRecordList()
      }
      if (val.name === 'faultRecord') {
        this.getFaultRecordList()
      }
      if (val.name === 'diagnosisRecord') {
        this.getDiagnosisRecordList()
      }
      if (val.name === 'decisionRecord') {
        this.getDecisionRecordList()
      }
    },
    // 运行记录
    getRecordList() {
      listRecord(this.recordQueryParams).then(response => {
        this.recordList = response.rows
        this.recordTotal = response.total
      })
    },
    /** 搜索按钮操作 */
    recordHandleQuery() {
      this.recordQueryParams.pageNum = 1
      this.getRecordList()
    },
    /** 重置按钮操作 */
    recordResetQuery() {
      this.resetForm('recordQueryForm')
      this.recordHandleQuery()
    },
    // 运行记录
    // 备品备件---
    getPartList() {
      listPart(this.partQueryParams).then(response => {
        this.partList = response.rows
        this.partTotal = response.total
      })
    },
    handlePartQuery() {
      this.partQueryParams.pageNum = 1
      this.getPartList()
    },
    resetPartQuery() {
      this.resetForm('partQueryForm')
      this.handlePartQuery()
    },
    handlePartAdd() {
      this.dialogVisible = true
      this.getAddPartList()
    },
    handleAddEquipPart() {
      if (this.partIds.length === 0) {
        this.$modal.msgSuccess('请选择备品备件')
        return
      }
      let params = {
        eqpId: this.partQueryParams.eqpId,
        sparePartIdList: this.partIds
      }
      addEquipPart(params).then(res => {
        this.$modal.msgSuccess('关联成功')
        this.dialogVisible = false
        this.getPartList()
      })
    },
    handleEquipPartClose() {
      this.$refs.multipleTable.clearSelection();  //清空
      this.dialogVisible = false
    },
    handlePartDelete() {
      this.$modal.confirm('是否确认移除设备备品备件ID为"' + this.removePartIds + '"的数据项？').then(() => {
        let params = {
          eqpId: this.partQueryParams.eqpId,
          sparePartIdList: this.removePartIds
        }
        return delEquipPart(params)
      }).then(() => {
        this.getPartList()
        this.$modal.msgSuccess('移除成功')
      }).catch(() => {
      })
    },
    getAddPartList() {
      listPart(this.addPartQueryParams).then(response => {
        this.addPartList = response.rows
        this.addPartTotal = response.total
        // 已勾选的进行回显
        this.$nextTick(() => {
          this.$refs.multipleTable.clearSelection();  //清空
          getBindSparePart(this.partQueryParams.eqpId).then(res => {
            let sparePartIds = res.data.map(item => item.sparePartId)
            this.addPartList.forEach(item => {
              if(sparePartIds.includes(item.sparePartId)){
                this.$refs.multipleTable.toggleRowSelection(item)
              }
            })
          })
        })
      })
    },
    handleAddPartQuery() {
      this.addPartQueryParams.pageNum = 1
      this.getAddPartList()
    },
    resetAddPartQuery() {
      this.resetForm('addPartQueryForm')
      this.handleAddPartQuery()
    },
    handlePartSelectionChange(selection) {
      this.partIds = selection.map(item => item.sparePartId)
    },
    handleRemovePartSelectionChange(selection) {
      this.removePartIds = selection.map(item => item.sparePartId)
      this.partMultiple = !selection.length
    },
    // 备品备件---
    // 状态评估---
    getStatusRecordList() {
      this.statusQueryParams.params = {}
      if (null != this.statusDaterangeExecTime && '' != this.statusDaterangeExecTime) {
        this.statusQueryParams.params['beginExecTime'] = this.statusDaterangeExecTime[0]
        this.statusQueryParams.params['endExecTime'] = this.statusDaterangeExecTime[1]
      }
      listAlgorithmRecord(this.statusQueryParams).then(response => {
        this.statusRecordList = response.rows
        this.statusTotal = response.total
      })
    },
    handleStatusQuery() {
      this.statusQueryParams.pageNum = 1
      this.getStatusRecordList()
    },
    resetStatusQuery() {
      this.statusDaterangeExecTime = []
      this.resetForm('statusQueryForm')
      this.handleStatusQuery()
    },
    // 状态评估---
    // 寿命预测---
    getLifeRecordList() {
      this.lifeQueryParams.params = {}
      if (null != this.lifeDaterangeExecTime && '' != this.lifeDaterangeExecTime) {
        this.lifeQueryParams.params['beginExecTime'] = this.lifeDaterangeExecTime[0]
        this.lifeQueryParams.params['endExecTime'] = this.lifeDaterangeExecTime[1]
      }
      listAlgorithmRecord(this.lifeQueryParams).then(response => {
        this.lifeRecordList = response.rows
        this.lifeTotal = response.total
      })
    },
    handleLifeQuery() {
      this.lifeQueryParams.pageNum = 1
      this.getLifeRecordList()
    },
    resetLifeQuery() {
      this.lifeDaterangeExecTime = []
      this.resetForm('lifeQueryForm')
      this.handleLifeQuery()
    },
    // 寿命预测---
    // 设备故障---
    getFaultRecordList() {
      this.faultQueryParams.params = {}
      if (null != this.faultDaterangeExecTime && '' != this.faultDaterangeExecTime) {
        this.faultQueryParams.params['beginExecTime'] = this.faultDaterangeExecTime[0]
        this.faultQueryParams.params['endExecTime'] = this.faultDaterangeExecTime[1]
      }
      listFaultRecord(this.faultQueryParams).then(response => {
        this.faultRecordList = response.rows
        this.faultTotal = response.total
      })
    },
    handleFaultQuery() {
      this.faultQueryParams.pageNum = 1
      this.getFaultRecordList()
    },
    resetFaultQuery() {
      this.faultDaterangeExecTime = []
      this.resetForm('faultQueryForm')
      this.handleFaultQuery()
    },
    // 设备故障---
    // 故障诊断---
    getDiagnosisRecordList() {
      this.diagnosisQueryParams.params = {}
      if (null != this.diagnosisDaterangeExecTime && '' != this.diagnosisDaterangeExecTime) {
        this.diagnosisQueryParams.params['beginExecTime'] = this.diagnosisDaterangeExecTime[0]
        this.diagnosisQueryParams.params['endExecTime'] = this.diagnosisDaterangeExecTime[1]
      }
      listAlgorithmRecord(this.diagnosisQueryParams).then(response => {
        this.diagnosisRecordList = response.rows
        this.diagnosisTotal = response.total
      })
    },
    handleDiagnosisQuery() {
      this.diagnosisQueryParams.pageNum = 1
      this.getDiagnosisRecordList()
    },
    resetDiagnosisQuery() {
      this.diagnosisDaterangeExecTime = []
      this.resetForm('diagnosisQueryForm')
      this.handleDiagnosisQuery()
    },
    // 故障诊断---
    // 维修决策---
    getDecisionRecordList() {
      this.decisionQueryParams.params = {}
      if (null != this.decisionDaterangeExecTime && '' != this.decisionDaterangeExecTime) {
        this.decisionQueryParams.params['beginExecTime'] = this.decisionDaterangeExecTime[0]
        this.decisionQueryParams.params['endExecTime'] = this.decisionDaterangeExecTime[1]
      }
      listAlgorithmRecord(this.decisionQueryParams).then(response => {
        this.decisionRecordList = response.rows
        this.decisionTotal = response.total
      })
    },
    handleDecisionQuery() {
      this.decisionQueryParams.pageNum = 1
      this.getDecisionRecordList()
    },
    resetDecisionQuery() {
      this.decisionDaterangeExecTime = []
      this.resetForm('decisionQueryForm')
      this.handleDecisionQuery()
    },
    // 维修决策---
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.getTreeSelect()
      this.open = true
      this.title = '添加设备'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      this.getTreeSelect()
      const eqpId = row.eqpId || this.ids
      getEquip(eqpId).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改设备'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.eqpId != null) {
            updateEquip(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addEquip(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const eqpIds = row.eqpId || this.ids
      this.$modal.confirm('是否确认删除设备编号为"' + eqpIds + '"的数据项？').then(function() {
        return delEquip(eqpIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('equipment/equip/export', {
        ...this.queryParams
      }, `equip_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
<style scoped lang="scss">
.form-overflow-hide {
  height: 70vh;
  padding: 8px;
  overflow-y: auto;
}
</style>
